// 后台首页统计接口
import request from '@/utils/request'

export type IPanels = {
  title: string
  value: number
  unit?: string
  unitColor?: string
  subTitle?: string
  subValue?: number | string
  subUnit?: string
}
export interface IData1 {
  panels: IPanels[]
}
export interface IResult1 {
  msg: string
  data: IData1
  path: string
}

export function reqGetStatistics1() {
  return request<IData1>({
    url: '/admin/statistics1',
    method: 'get'
  })
}

export function reqGetStatistics2() {
  return request({
    url: '/admin/statistics2',
    method: 'get'
  })
}

// type	hour	String	是	统计类型：month近1个月、week近1周、hour近24小时
export function reqGetStatistics3(data: { type: string }) {
  return request({
    url: '/admin/statistics3', // ?type=month
    method: 'get',
    data
  })
}

export function reqGetStatistics1_bak() {
  // 增加返回数据类型约定
  return new Promise(
    (
      resolve: (value: IResult1 | PromiseLike<IResult1>) => void
      // reject: (reason?: { msg: string; data?: string; path: string }) => void,
    ) => {
      setTimeout(() => {
        resolve({
          msg: 'ok',
          data: {
            panels: [
              {
                title: '支付订单',
                value: 51,
                unit: '年',
                unitColor: 'success',
                subTitle: '总支付订单',
                subValue: 51,
                subUnit: ''
              },
              {
                title: '订单量',
                value: 555,
                unit: '周',
                unitColor: 'danger',
                subTitle: '转化率',
                subValue: '60%',
                subUnit: ''
              },
              {
                title: '销售额',
                value: 3.74,
                unit: '年',
                unitColor: '',
                subTitle: '总销售额',
                subValue: 3.74,
                subUnit: ''
              },
              {
                title: '新增用户',
                value: 19,
                unit: '年',
                unitColor: 'warning',
                subTitle: '总用户',
                subValue: 19,
                subUnit: '人'
              }
            ]
          },
          path: 'https://study.163.com/course/courseMain.htm?courseId=1212775807&share=2&shareId=480000001892585'
        })
      })
    }
  )
}

export function reqGetStatistics2_bak() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        msg: 'ok',
        data: {
          goods: [
            {
              label: '审核中',
              value: 2
            },
            {
              label: '销售中',
              value: 22
            },
            {
              label: '已下架',
              value: 13
            },
            {
              label: '库存预警',
              value: 0
            }
          ],
          order: [
            {
              label: '待付款',
              value: 171
            },
            {
              label: '待发货',
              value: 16
            },
            {
              label: '已发货',
              value: 1
            },
            {
              label: '退款中',
              value: 17
            }
          ]
        }
      })
    })
  })
}
